<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"          			
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      >
    <ui:composition template="TaskProLayout.xhtml">
        <ui:define name="content">
            <!-- Filter form START -->
            <div class="Post">
                <h:form id="filter">
                    <h:panelGrid columns="3" cellpadding="3"  style="width: 600px;height: 100px">
                        <h:outputText value="Select subject" />
                        <p:selectOneMenu value="#{reportStudentBean.selectedSubjectCode}" effect="fade" style="width: 150px">   
                            <f:selectItem itemLabel="Select subject" itemValue="" />  
                            <f:selectItems value="#{reportStudentBean.subjects}" var="subject" itemLabel="#{subject.code}" itemValue="#{subject.code}"/>  
                        </p:selectOneMenu> 
                        <p:commandButton value="Choose subject" action="#{reportStudentBean.chooseSubject()}" ajax="true" update=":filter" style="width: 150px"/>   
                        <h:outputText value="Select group" />
                        <p:selectOneMenu value="#{reportStudentBean.selectedGroupCode}" effect="fade" style="width: 150px">   
                            <f:selectItem itemLabel="Select student" itemValue="" />  
                            <f:selectItems value="#{reportStudentBean.subjectGroup}" var="group" itemLabel="#{group.code} " itemValue="#{group.code}"/>  
                        </p:selectOneMenu> 
                        <p:commandButton value="Choose group" action="#{reportStudentBean.chooseGroup()}" ajax="true" update=":filter" style="width: 150px"/>   
                        <h:outputText value="Select student" />
                        <p:selectOneMenu value="#{reportStudentBean.selectedStudentLogin}" effect="fade" style="width: 150px">   
                            <f:selectItem itemLabel="Select student" itemValue="" />  
                            <f:selectItems value="#{reportStudentBean.kantorStudents}" var="student" itemLabel="#{student.login} #{student.name} #{student.surname}" itemValue="#{student.login}"/>  
                        </p:selectOneMenu> 
                        <p:commandButton value="Create report" action="#{reportStudentBean.chooseStudent()}" ajax="true" update=":taskForm,:submitPersonalForm,:unSubmitTeam,:unSubmitPersonal,:reportForm" style="width: 150px"/>   
                    </h:panelGrid> 
                </h:form>
            </div>
            <!-- Filter form END -->

            <!-- Statistic of selected student START -->
            <div class="Post">
                <h:form id="reportForm">
                    <h:panelGrid columns="6"  style="margin-bottom:10px;width: 800px" cellpadding="5">
                        <h:outputText value="Student :"/>
                        <h:outputText value="#{reportStudentBean.selectedStudent.name} #{reportStudentBean.selectedStudent.surname}" />
                        <h:outputText value="Number of team submitted task :"/>
                        <h:outputText value="#{reportStudentBean.submitTeamAssignment.size()}"/>
                        <h:outputText value="Total team score :"/>
                        <h:outputText value="#{reportStudentBean.submitTeamScore}"/>
                        <h:outputText value="E-mail :"/>
                        <h:outputText value="#{reportStudentBean.selectedStudent.email}" />
                        <h:outputText value="Number of team unsubmitted task :"/>
                        <h:outputText value="#{reportStudentBean.unSubmitTeamAssingment.size()}"/>
                        <h:outputText value="Total personal score :"/>
                        <h:outputText value="#{reportStudentBean.submitPersonalScore}"/>
                        <h:outputText value="Login :"/>
                        <h:outputText value="#{reportStudentBean.selectedStudent.login}" />
                        <h:outputText value="Number of personal submitted task :"/>
                        <h:outputText value="#{reportStudentBean.submitPersonalAssignmet.size()}"/>
                        <h:outputText value="Total earned score"/>
                        <h:outputText value="#{reportStudentBean.totalEarnedScore}"/>
                        <h:outputText value=""/>
                        <h:outputText value="" />
                        <h:outputText value="Number of personal unsubmitted task :"/>
                        <h:outputText value="#{reportStudentBean.unSubmitPersonAssingment.size()}"/>
                        <h:outputText value="Total score which could be earned :"/>
                        <h:outputText value="#{reportStudentBean.totalScore}"/>
                    </h:panelGrid>
                </h:form>
            </div>
            <!-- Statistic of selected student END -->

            <!-- Submitted team task datatable of selected student START -->
            <div class="Post">
                <h:form id="taskForm">  
                    <p:dataTable  var="task" value="#{reportStudentBean.submitTeamAssignment}"  
                                  selection="#{reportStudentBean.selectedSubmitTask}" selectionMode="single" paginatorAlwaysVisible="false"
                                  styleClass="facesFont"
                                  emptyMessage="No task was founded"
                                  paginator="true" rows="10"
                                  rowKey="#{task.id}">  
                        <p:ajax event="rowSelect"  
                                update=":submitTaskDetail:displaySubmit"  oncomplete="submitTaskDialog.show()"/>          
                        <f:facet name="header">  
                            <h:outputText value="Team submit task " style="font-size: 12px"/>
                        </f:facet>  
                        <p:column headerText="Label">                   
                            <h:outputText value="#{task.assignment.template.name}" />  
                        </p:column>     
                        <p:column headerText="Date of submit">  
                            <h:outputText value="#{task.dateOfSubmit}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Deadline">  
                            <h:outputText value="#{task.assignment.deadline}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Assigned">                    
                            <h:outputText value="#{task.assignment.dateOfAssignment}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="State">  
                            <h:outputText value="#{task.stateOfTask}" >                     
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Type">                  
                            <h:outputText value="#{task.assignment.type}" />
                        </p:column>  
                        <p:column headerText="Subject">  
                            <h:outputText value="#{task.assignment.subject.code}" >                     
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Grade">  
                            <h:outputText value="#{task.grade}" >                     
                            </h:outputText>
                        </p:column>  
                        <f:facet name="footer">
                            <p:summaryRow>  
                                <p:column colspan="7" style="text-align:right">  
                                    Total:  
                                </p:column> 
                                <p:column>  
                                    #{reportStudentBean.submitTeamScore}
                                </p:column>  
                            </p:summaryRow>  
                        </f:facet>
                    </p:dataTable>  
                </h:form>
            </div>
            <!-- Submitted team task datatable of selected student END -->

            <!-- Submitted personal task datatable of selected student START -->
            <div class="Post">
                <h:form id="submitPersonalForm">  
                    <p:dataTable  var="taskSubmitPer" value="#{reportStudentBean.submitPersonalAssignmet}"  
                                  selection="#{reportStudentBean.selectedSubmitTask}" selectionMode="single" paginatorAlwaysVisible="false"
                                  styleClass="facesFont"
                                  emptyMessage="No task was founded"
                                  paginator="true" rows="10"
                                  rowKey="#{taskSubmitPer.id}">  
                        <p:ajax event="rowSelect"  
                                update=":submitTaskDetail:displaySubmit"  oncomplete="submitTaskDialog.show()"/>          
                        <f:facet name="header">  
                            <h:outputText value="Personal submit task " style="font-size: 12px"/>
                        </f:facet>  
                        <p:column headerText="Label">                   
                            <h:outputText value="#{taskSubmitPer.assignment.template.name}" />  
                        </p:column>  
                        <p:column headerText="Date of submit">  
                            <h:outputText value="#{taskSubmitPer.dateOfSubmit}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Deadline">  
                            <h:outputText value="#{taskSubmitPer.assignment.deadline}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Assigned">                    
                            <h:outputText value="#{taskSubmitPer.assignment.dateOfAssignment}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="State">  
                            <h:outputText value="#{taskSubmitPer.stateOfTask}" >                     
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Type">                  
                            <h:outputText value="#{taskSubmitPer.assignment.type}" />
                        </p:column>  
                        <p:column headerText="Subject">  
                            <h:outputText value="#{taskSubmitPer.assignment.subject.code}" >                     
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Grade">  
                            <h:outputText value="#{taskSubmitPer.grade}" >                     
                            </h:outputText>
                        </p:column>  
                        <f:facet name="footer">
                            <p:summaryRow>  
                                <p:column colspan="7" style="text-align:right">  
                                    Total:  
                                </p:column>  
                                <p:column>  
                                    #{reportStudentBean.submitPersonalScore}  
                                </p:column>  
                            </p:summaryRow> 
                        </f:facet>
                    </p:dataTable>  
                </h:form>
            </div>
            <!-- Submitted personal task datatable of selected student END -->

            <!-- Unsubmitted personal task datatable of selected student START -->
            <div class="Post">
                <h:form id="unSubmitPersonal">
                    <p:dataTable 
                        var="taskUnSubmitPer" value="#{reportStudentBean.unSubmitPersonAssingment}" paginator="true" rows="10"  
                        selection="#{reportStudentBean.selectUnsubmitTask}" selectionMode="single"  
                        rowKey="#{taskUnSubmitPer.id}" paginatorAlwaysVisible="false"
                        widgetVar="unSubmitPersonalTask" emptyMessage="No task was founded"
                        >  
                        <p:ajax event="rowSelect"  
                                update=":unSubmitDetail:display,:unSubmitDetail:templateFileTable"  oncomplete="unsubmitTaskDialog.show()" />    
                        <f:facet name="header">  
                            <h:outputText value="Unsubmit personal task" />
                        </f:facet>  
                        <p:column headerText="Label" >  
                            <h:outputText value="#{taskUnSubmitPer.template.name}" />  
                        </p:column>   
                        <p:column headerText="Date of assignment">    
                            <h:outputText value="#{taskUnSubmitPer.dateOfAssignment}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Deadline">  
                            <h:outputText value="#{taskUnSubmitPer.deadline}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Type">                      
                            <h:outputText value="#{taskUnSubmitPer.type}" /> 
                        </p:column>
                        <p:column headerText="Kantor">            
                            <h:outputText value="#{taskUnSubmitPer.template.kantor.name} #{taskUnSubmitPer.template.kantor.surname}" /> 
                        </p:column>
                        <p:column headerText="Subject">   
                            <h:outputText value="#{taskUnSubmitPer.subject.code}" /> 
                        </p:column>
                    </p:dataTable>   
                </h:form>  
            </div>
            <!-- Unsibmitted personal task datatable of selected student END -->

            <!-- Unsubmitted team task datatable of selected student START -->
            <div class="Post">
                <h:form id="unSubmitTeam">
                    <p:dataTable 
                        var="taskUnSubTeam" value="#{reportStudentBean.unSubmitTeamAssingment}" paginator="true" rows="10"  
                        selection="#{reportStudentBean.selectUnsubmitTask}" selectionMode="single"  
                        rowKey="#{taskUnSubTeam.id}" paginatorAlwaysVisible="false"
                        widgetVar="unSubmitPersonalTask" emptyMessage="No task was founded"
                        >  
                        <p:ajax event="rowSelect"  
                                update=":unSubmitDetail:display,:unSubmitDetail:templateFileTable"  oncomplete="unsubmitTaskDialog.show()" />    
                        <f:facet name="header">  
                            <h:outputText value="Unsubmit team task" />
                        </f:facet>  
                        <p:column headerText="Label" >  
                            <h:outputText value="#{taskUnSubTeam.template.name}" />  
                        </p:column>   
                        <p:column headerText="Date of assignment">    
                            <h:outputText value="#{taskUnSubTeam.dateOfAssignment}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Deadline">  
                            <h:outputText value="#{taskUnSubTeam.deadline}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Type">                      
                            <h:outputText value="#{taskUnSubTeam.type}" /> 
                        </p:column>
                        <p:column headerText="Kantor">            
                            <h:outputText value="#{taskUnSubTeam.template.kantor.name} #{taskUnSubTeam.template.kantor.surname}" /> 
                        </p:column>
                        <p:column headerText="Subject">   
                            <h:outputText value="#{taskUnSubTeam.subject.code}" /> 
                        </p:column>
                    </p:dataTable>   
                </h:form>  
            </div>
            <!-- Unsubmitted team task datatable of selected student END -->

            <!-- Unsubmitted task detai dialog START -->
            <p:dialog header="Task Detail" widgetVar="unsubmitTaskDialog" resizable="true"  modal="true"
                      width="900" height="600" dynamic="true" appendToBody="true" > 
                <h:form id="unSubmitDetail">
                    <h:panelGrid id="display" columns="2" cellpadding="4" title="Assigned Task">  
                        <h:outputText value="Label"/>
                        <h:outputText value="#{reportStudentBean.selectUnsubmitTask.template.name}" />
                        <h:outputText value="Description"/>
                        <h:outputText  value="#{reportStudentBean.selectUnsubmitTask.template.description}" escape="false">
                            <f:converter converterId="StringFormatter"/>
                        </h:outputText>
                        <h:outputText value="Deadline"/>
                        <h:outputText value="#{reportStudentBean.selectUnsubmitTask.deadline}" >
                            <f:convertDateTime  ></f:convertDateTime>
                        </h:outputText>
                        <h:outputText value="Kantor:"/>                           
                        <h:outputText value="#{reportStudentBean.selectUnsubmitTask.template.kantor.name} 
                                      #{reportStudentBean.selectUnsubmitTask.template.kantor.surname}" />
                        <h:outputText value="Kantor e-mail:" />
                        <h:outputText value="#{reportStudentBean.selectUnsubmitTask.template.kantor.email}" />
                    </h:panelGrid>  
                    <p:dataTable id="templateFileTable" value="#{reportStudentBean.selectUnsubmitTask.template.templateFiles}" var="tFile"
                                 rowKey="#{tFile.id}" emptyMessage="No files were added to this task by kantor">
                        <f:facet name="header">
                            <h:outputText value="Assignment files" />
                        </f:facet>
                        <p:column headerText="File name">
                            <h:outputText value="#{tFile.fileName}" />
                        </p:column>
                        <p:column headerText="File size">
                            <h:outputText value="#{tFile.fileSize}" />
                        </p:column>
                        <p:column headerText="Action">
                            <p:commandButton value="Download" ajax="false">
                                <p:fileDownload id="koko" value="#{reportStudentBean.download(tFile)}"/>
                            </p:commandButton>    
                        </p:column>
                    </p:dataTable>
                    <p:commandButton value="Close"  onclick="unsubmitTaskDialog.close()"
                                     ajax="true"></p:commandButton>
                </h:form>
            </p:dialog>   
            <!-- Unsubmitted task detai dialog END -->     

            <!-- Submiteed task detai dialog START -->
            <p:dialog header="Task detail: #{reportStudentBean.selectedSubmitTask.assignment.template.name}" widgetVar="submitTaskDialog" resizable="false" 
                      width="900" height="600"  modal="true" appendToBody="true"
                      dynamic="true" >  
                <h:form id="submitTaskDetail">
                    <h:panelGrid id="displaySubmit" columns="2" cellpadding="4" title="Assigned Task">  
                        <h:outputText value="Label"/>
                        <h:outputText value="#{reportStudentBean.selectedSubmitTask.assignment.template.name}" />
                        <h:outputText value="Description"/>
                        <h:outputText value="#{reportStudentBean.selectedSubmitTask.assignment.template.description}" escape="false" >
                            <f:converter converterId="StringFormatter" />
                        </h:outputText>
                        <h:outputText value="Subject"/>
                        <h:outputText value="#{reportStudentBean.selectedSubmitTask.assignment.subject.code}" />
                        <h:outputText value="Date of assign:"/>
                        <h:outputText value="#{reportStudentBean.selectedSubmitTask.assignment.dateOfAssignment}" >
                            <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                        </h:outputText>
                        <h:outputText value="Deadline"/>
                        <h:outputText value="#{reportStudentBean.selectedSubmitTask.assignment.deadline}" >
                            <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                        </h:outputText>            
                        <h:outputText value="Date of submit:"/>
                        <h:outputText value="#{reportStudentBean.selectedSubmitTask.dateOfSubmit}" >
                            <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                        </h:outputText>
                        <h:outputText value="Template files" />
                        <p:commandButton value="Template file"  ajax="true"  onclick="fileDialog.show();" update=":templateFiles"/> 
                        <h:outputText value="Files" />
                        <p:commandButton value="Files with task" action="#{reportStudentBean.loadVersion()}" ajax="true"  onclick="dlg1.show();" update=":dialogFiles"/> 
                        <h:outputText value="Evaluation" />
                        <h:outputText value="#{reportStudentBean.selectedSubmitTask.evaluation}" />
                        <h:outputText value="Grade:" />
                        <h:outputText value="#{reportStudentBean.selectedSubmitTask.grade}" />
                    </h:panelGrid>  
                    <p:commandButton value="Close"  
                                     ajax="true" onclick="submitTaskDialog.hide();"></p:commandButton>
                </h:form>
            </p:dialog>   
            <!-- Submitted task detai dialog END -->

            <!-- Submitted files with selected task. Detai dialog START -->
            <p:dialog width="870" height="400" header="Submitted with task: #{reportStudentBean.selectedSubmitTask.assignment.template.name}"
                      widgetVar="dlg1" modal="true" dynamic="true" appendToBody="true"
                      >
                <h:form id="dialogFiles">
                    <p:dataTable var="taskFile" value="#{reportStudentBean.versionFiles}" id="dialogFiles"
                                 rowKey="#{taskFile.id}" paginator="true" 
                                 paginatorAlwaysVisible="false" rows="10" >  
                        <p:column headerText="File" >  
                            <p:commandLink value="#{taskFile.fileName}" ajax="false">  
                                <p:fileDownload value="#{reportStudentBean.downloadFilesByTask(taskFile)}" />  
                            </p:commandLink> 
                        </p:column>
                        <p:column headerText="Size" >  
                            <h:outputText title="size" value="#{taskFile.fileSize}"  >
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Description">  
                            <h:outputText value="#{taskFile.description}" escape="false">
                                <f:converter converterId="StringFormatter" />
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Date of submit">  
                            <h:outputText value="#{taskFile.version.dateOfSubmit}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Number of version">  
                            <h:outputText value="#{taskFile.version.numberOfVersion}" />  
                        </p:column>
                        <p:column headerText="Sender">  
                            <h:outputText value="#{taskFile.version.submittedStudent.name} #{taskFile.version.submittedStudent.surname}" />  
                        </p:column>
                        <p:column headerText="Download">  
                            <p:commandButton value="Download" ajax="false">  
                                <p:fileDownload value="#{reportStudentBean.downloadFilesByTask(taskFile)}" />  
                            </p:commandButton> 
                        </p:column> 
                    </p:dataTable>
                    <p:commandButton value="Close" onclick="dlg1.hide()" />
                </h:form>
            </p:dialog>                 
            <!-- Submitted files with selected task. Detai dialog END -->

            <!-- Template files with selected task. Detai dialog START -->
            <p:dialog width="850" height="400" header="Template files with task: #{reportStudentBean.selectedSubmitTask.assignment.template.name}"
                      widgetVar="fileDialog" modal="true" dynamic="true" appendToBody="true"
                      >
                <h:form  id="templateFiles">
                    <p:dataTable var="templateFile" value="#{reportStudentBean.selectedSubmitTask.assignment.template.templateFiles}"
                                 rowKey="#{templateFile.id}" paginator="true" 
                                 paginatorAlwaysVisible="false" rows="10" >  
                        <p:column headerText="File" >  
                            <h:outputText title="file" value="#{templateFile.fileName}"  >
                                <f:converter converterId="StringConverter" />
                            </h:outputText>
                        </p:column>
                        <p:column headerText="File" >  
                            <h:outputText title="file" value="#{templateFile.fileSize}"  />  
                        </p:column>
                        <p:column headerText="Download">  
                            <p:commandButton value="Download" ajax="false">  
                                <p:fileDownload value="#{reportStudentBean.download(templateFile)}" />  
                            </p:commandButton> 
                        </p:column> 
                    </p:dataTable>
                </h:form>
            </p:dialog>
            <!-- Template files with selected task. Detai dialog END -->
        </ui:define>
    </ui:composition>
</html>